<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="js/public.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/font.js"></script>
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/ui.css">
    <title></title>
    <!-- 忘记密码 -->
</head>
<body>
<div class="scroll-content2 login-forget" style="overflow:auto;background: #F6F6F8;">
    <div class="top-public">
        <span class="public-center">忘记密码</span>        
        <img src="images/left_icon.png" alt="" class="public-left">
    </div>
    <div class="top">
        <ul>
            <li><input type="text" name="" id="Phone" placeholder="请输入手机号"></li>
            <li><input type="text" name="" id="Code" placeholder="请输入手机验证码"><span class="get-code" onclick="codeVerification()">获取验证码</span></li>
        </ul>
        <ul>
            <li><input type="text" id="Pass" placeholder="新密码"><img src="images/gray_3.png" alt="" class="eye"></li>
            <li><input type="text" id="twoPass" placeholder="确认密码"><img src="images/gray_3.png" alt="" class="eye"></li>
        </ul>
    </div>
    <div class="confirm" onclick="forget()">确定</div>
</div>
</body>
<script>
    $('.public-left').click(function(){
        window.history.go(-1);
    });
    var myreg = /^1[3|4|5|7|8][0-9]{9}$/;

    function codeVerification() {
        var mobile = $('#Phone').val();
        if (mobile == '') {
            alert('手机号不能为空');
            return false;
        } if (!myreg.test(mobile)) {
            alert('请输入正确的手机号');
            return false;
        }
        $.ajax({
            url: url() + 'api/admin/sendsms', //请求的url地址
            dataType: "JSON", //返回格式为json
            async: true, //请求是否异步，默认为异步，这也是ajax重要特性
            type: "post", //请求方式
            data:{
                mobile:mobile,
            },
            success: function (data) {
                console.log(data)
                //请求成功时处理
                if(data.status == 1){
                    alert('成功获取验证码！');
                }if (data.status == -1) {
                    alert(data.msg);
                    return false;
                }
            }
        });
    }

    function forget() {
        var mobile = $('#Phone').val();
        var Code = $('#Code').val();
        var Password = $('#Pass').val();
        var twoPass = $('#twoPass').val();
        if (mobile == '') {
            alert('手机号不能为空');
            return false;
        } else if (!myreg.test(mobile)) {
            alert('请输入正确的手机号');
            return false;
        } else if (Password == '') {
            alert('密码不能为空');
            return false;
        } else if(twoPass=='') {
            alert('两次密码不一致');
            return false;
        } else if (Password != twoPass) {
            alert('两次密码不一致');
            return false;
        } else {
            $.ajax({
                url: url() + 'api/admin/forget', //请求的url地址
                dataType: "JSON", //返回格式为json
                async: true, //请求是否异步，默认为异步，这也是ajax重要特性
                type: "post", //请求方式
                data:{
                    mobile:mobile,
                    password:Password,
                    code:Code,
                },
                success: function (data) {
                    //请求成功时处理
                    if(data.status == 1){
                        alert('修改成功，请登录！');
                        window.location.href='login.html';
                    }if (data.status == -1) {
                        alert(data.msg);
                        return false;
                    }
                }
            });
        }
    }

</script>
</html> 






